#!/bin/sh
#->
#  Name:		uninstall
VERSION='0.1'
#  Modified:	Wed Oct 13 2010, 03:46:24
#  Insects:		What species? No bugs known,yet.

#  Feel free to contact me at:
#  <http://sites.google.com/site/code933k>
#  in case of bugs, updates, proposals or comments

#  Copyright (C) 2010 Mario García H.
 
#  "THE BEER-WARE LICENSE" (Revision 42):
#  <code933k (AT) gmail> wrote this file. As long as you retain
#  this notice you can do whatever you want with this stuff.

#  If we meet some day, and you think this stuff is worth it,
#  you can buy me a BEER in return, Mario García H.

#  THIS IS FREE SOFTWARE
#  THERE IS NO WARRANTY, TO THE EXTENT PERMITTED BY LAW.
#<-

function uninstall_error(){
	printf "\033[01;31mERROR:  \033[m$*\n"
	exit 1
}

function remove_all(){
    local ANSWER=no

    echo '________________________________________________'
    echo 'WARNING!!'
    echo 'I will remove (all files and dirs in this paths)'
    echo '________________________________________________'
    echo

    for installed in $(cat ".install.rec" 2>/dev/null)
	do
        echo $installed \
		|| uninstall_error "Cannot read .install.rec CHECK USER PERMISSION"
	done

    printf "\nDo you want me to continue? [yes](default: no) "

    read ANSWER
    if test "$ANSWER" == yes
    then
        for installed in $(cat ".install.rec" 2>/dev/null)
        do
            rm -rvI -- $installed \
            || uninstall_error "Cannot remove $dir. CHECK USER PERMISSION"
        done
    fi

	return 0
}


# UNINSTALL
# help
case $1 in
	-h|h|-help|--help|help)
        echo
        echo "Simple uninstall.sh $VERSION, for linuxrules"
        echo
        echo 'usage:'
        echo 'In the same location $PWD/$PATH you ran ./install.sh'
        echo 'Issue, ./uninstall.sh'
        echo
        echo 'To uninstall manually just read the contents of'
        echo '.install.rec and remove files by hand'
        echo
        echo '# THIS IS FREE SOFTWARE'
        echo '# THERE IS NO WARRANTY, TO THE EXTENT PERMITTED BY LAW.'
        echo 'Copyright (C) 2010 Mario García H.'
        echo 'License Beerware'
        echo
        exit 0
	;;
esac

remove_all

exit 0
